import { requestClient } from '#/api/request'
import type { ApiPagination, ApiPaginationParams } from '#types/utils'
import { EnumSaleOrderSource } from './../../config/enum/saleOrder'
import type { ExportTaskLogListItem, ExportTaskLogVo, SalesOrderListItem } from './model/salesOrder'

// 销售订单接口
export default class TradeSalesOrderApi {
    // 获取单例
    static get inst() {
        return TradeSalesOrderApi._inst || (TradeSalesOrderApi._inst = new TradeSalesOrderApi())
    }
    private static _inst: TradeSalesOrderApi

    /**
     * 审核
     * @param data
     */
    approval(data: {
        /**
         * 审核消息
         */
        approvalMessage?: string
        /**
         * 审批状态 2.审批通过 3.审批失败
         */
        approvalStatus: number
        /**
         * 审批id列表
         */
        ids: number[]
    }) {
        return requestClient.put<boolean>('/orders/approval', data)
    }

    delete(ids: Array<number | string>) {
        return requestClient.get<null>(`/orders/deleteOrder?id=${ids}`)
    }

    edit(params: Partial<SalesOrderListItem>) {
        return requestClient.put<null>('/orders/edit', params)
    }

    /**
     * 导入详情 可以获取是否成功
     * @param id
     */
    getImportDetail(id: number | string) {
        return requestClient.get<ExportTaskLogVo>('/orders/exportTaskLog/detail', {
            params: { id }
        })
    }

    /**
     * 分页查询下载或者导入日志列表  导入记录
     */
    getImportRecord(params: ApiPaginationParams<undefined>) {
        return requestClient.post<ExportTaskLogListItem>('/orders/exportTaskLog/list', params)
    }
    /**
     * 列表分页
     */
    getPageList(params: ApiPaginationParams<{ username?: string }>) {
        // return {
        //     total: 1,
        //     records: [
        //         {
        //             id: 36,
        //             sellerUserId: 4,
        //             sellerName: '塞家豪',
        //             taskId: 4,
        //             taskName: '塞家豪',
        //             authorId: 82,
        //             ordersNo: 'Ut',
        //             goodsName: '夏侯榕融',
        //             goodsCode: '12',
        //             saleTime: '1971-11-07 06:51:12',
        //             saleNum: 73,
        //             salePrice: 600.45,
        //             extendUrl: 'https://mysterious-lotion.net/',
        //             prospectPlatformPrice: 695.65,
        //             prospectAuthorPrice: 821.99,
        //             importType: 93,
        //             source: 3,
        //             channelId: 8,
        //             approvalStatus: 1,
        //             approvalUser: 'in',
        //             createTime: '1983-09-08 21:37:59',
        //             sellerUserName: '碧鲁辉',
        //             companyName: '帅瑜',
        //             publishManager: 'in labore nulla in deserunt',
        //             country: 'fugiat ullamco voluptate esse',
        //             thirdPartyComm: 33,
        //             title: '仿佛设备耶耶耶同样地少举帽子多保龄球',
        //             vertical: 'magna Duis',
        //             influencer: 'in eiusmod',
        //             contact: 'eiusmod consequat nulla sit',
        //             influencerAuthorName: '创作者2',
        //             influencerPlatformName: '嬴国辉'
        //         },
        //         {
        //             id: 55,
        //             sellerUserId: 1,
        //             sellerName: '嘉建华',
        //             taskId: 6,
        //             taskName: '腾一全',
        //             authorId: 83,
        //             ordersNo: 'sint veniam quis sed Excepteur',
        //             goodsName: '詹桂英',
        //             goodsCode: '94',
        //             saleTime: '1990-06-15 14:05:31',
        //             saleNum: 2,
        //             salePrice: 555.09,
        //             extendUrl: 'https://tender-casket.name/',
        //             prospectPlatformPrice: 248.69,
        //             prospectAuthorPrice: 207.59,
        //             importType: 96,
        //             source: 3,
        //             channelId: 50,
        //             approvalStatus: 2,
        //             approvalUser: 'nulla exercitation magna incididunt',
        //             createTime: '2021-11-22 22:41:16',
        //             sellerUserName: '雀丽芳',
        //             companyName: '烟安琪',
        //             publishManager: 'pariatur qui aute enim do',
        //             country: 'sit tempor sunt cupidatat',
        //             thirdPartyComm: 98,
        //             title: '敢情横穿手镯剪',
        //             vertical: 'laborum consectetur ut in',
        //             influencer: 'ullamco',
        //             contact: 'do fugiat',
        //             influencerAuthorName: '逢鑫',
        //             influencerPlatformName: '牢波'
        //         },
        //         {
        //             id: 67,
        //             sellerUserId: 18,
        //             sellerName: '泷丽芬',
        //             taskId: 78,
        //             taskName: '墨梓晨',
        //             authorId: 26,
        //             ordersNo: 'anim consequat',
        //             goodsName: '有国香',
        //             goodsCode: '31',
        //             saleTime: '2015-08-09 07:44:45',
        //             saleNum: 38,
        //             salePrice: 511.45,
        //             extendUrl: 'https://honored-cleaner.info/',
        //             prospectPlatformPrice: 444.19,
        //             prospectAuthorPrice: 384.29,
        //             importType: 68,
        //             source: 1,
        //             channelId: 23,
        //             approvalStatus: 3,
        //             approvalUser: 'irure amet et Duis',
        //             createTime: '2021-02-04 14:08:32',
        //             sellerUserName: '练建军',
        //             companyName: '水国琴',
        //             publishManager: 'cupidatat laboris',
        //             country: 'mollit et ut sint',
        //             thirdPartyComm: 27,
        //             title: '相反一同简直赦免唉',
        //             vertical: 'deserunt laboris officia amet',
        //             influencer: 'occaecat sint dolore',
        //             contact: 'nostrud culpa Ut mollit',
        //             influencerAuthorName: '霍熙成',
        //             influencerPlatformName: '衡蒙'
        //         }
        //     ]
        // }
        return requestClient.get<ApiPagination<SalesOrderListItem>>('/orders/index', {
            params
        })
    }

    // 上传文件
    upload(data: { file: File; source?: EnumSaleOrderSource }) {
        // 使用requestClient的put方法，上传文件到/orders/importOrders接口，data为上传的文件，headers为请求头，'Content-Type'为multipart/form-data
        return requestClient.put<number>(
            `/orders/importOrders?source=${data.source ?? EnumSaleOrderSource.PLATFORM}`,
            { file: data.file },
            {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            }
        )
    }
}
